package com.uniinnovate.lanjingling.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.uniinnovate.lanjingling.entity.UserEntity;
import com.uniinnovate.lanjingling.pojo.vo.JobVO;
import com.uniinnovate.lanjingling.service.JobApplicationService;
import com.uniinnovate.lanjingling.service.JobService;
import com.uniinnovate.lanjingling.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.uniinnovate.lanjingling.entity.CompanyEntity;
import com.uniinnovate.lanjingling.service.CompanyService;
import com.uniinnovate.lanjingling.utils.PageUtils;
import com.uniinnovate.lanjingling.utils.R;


/**
 * @author LianChuangTech
 * @email LianChuangTech@163.com
 */
@Api(tags = "企业相关")
@RestController
@RequestMapping("/lanjingling/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @Autowired
    private JobService jobService;

    @Autowired
    private JobApplicationService jobApplicationService;

    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @ApiOperation("查询企业列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = companyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("查询企业信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        CompanyEntity company = companyService.getById(id);

        return R.ok().put("company", company);
    }

    /**
     * 保存
     */
    @ApiOperation("保存企业信息")
    @PostMapping("/save")
    public R save(@RequestBody CompanyEntity company) {
        companyService.save(company);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改企业信息")
    @PutMapping("/update")
    public R update(@RequestBody CompanyEntity company) {
        companyService.updateById(company);

        return R.ok();
    }

    /**
     * 批量删除
     */
    @ApiOperation("批量删除企业信息")
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        companyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 指定删除
     */
    @ApiOperation("指定删除企业信息")
    @DeleteMapping("/deleteById/{id}")
    public R deleteById(@PathVariable("id") Long id) {
        companyService.removeById(id);

        return R.ok();
    }

    /**
     * 上传职位
     */
    @ApiOperation("上传职位")
    @PostMapping("/uploadJob")
    public R uploadJob(@RequestBody JobVO jobVO) {
        return companyService.uploadJob(jobVO);
    }

    /**
     * 查看消息
     */
    @ApiOperation("查看消息")
    @GetMapping("/browseMsg")
    public R browseMsg(@RequestParam("userId") Long userId) {

        return R.ok();
    }

    /**
     * 根据id获取工作列表
     */
    @ApiOperation("根据id获取工作列表")
    @GetMapping("/listJob")
    public R listJob(@RequestParam("id") Long id) {
        return jobService.listJob(id);
    }

    /**
     * 根据id获取申请列表
     */
    @ApiOperation("根据id获取申请列表")
    @GetMapping("/listApply")
    public R listApply(@ApiParam("企业id") @RequestParam("id") Long id) {
        // 根据 id 获取工作列表，在根据job_id获取申请列表
        return jobApplicationService.listApply(id);
    }

    /**
     * 审核职位申请
     */
    @ApiOperation("审核职位申请")
    @GetMapping("/auditApply")
    public R auditApply(@ApiParam("职位申请id") @RequestParam("applyId") Long applyId) {
        return R.ok();
    }

    /**
     * 查看用户信息
     */
    @ApiOperation("查看用户信息")
    @GetMapping("/browseUser")
    public R browseUser(@ApiParam("用户id") @RequestParam("userId") Long userId) {
        UserEntity user = userService.getById(userId);
        Map<String, Object> map = new HashMap<>();
        map.put("data", user);
        return R.ok(map);
    }

}
